Skip to contentSkip to conversation

Change in openvpn[master]: ssl: change return type of calc_control_channel_frame_overhead to size_t

Openvpn-devel In review flichtenheld (Code Review) 2 participants 6 messages Oct 24, 2025 – Nov 12, 2025 1 message not in the archive

lore
Share & tools
lore

A message that is not in the archive (sent off-list or not yet received): gerrit.1761324750000.I71e9d4a61d37483685723c16e98f59755694cadf@...2715...

#1 lore raw

Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1297?usp=email

to review the following change.

Change subject: ssl: change return type of calc_control_channel_frame_overhead to size_t
......................................................................

ssl: change return type of calc_control_channel_frame_overhead to size_t

This avoids dealing with conversion warnings inside the function. Since we only add values that are supposed to be positive this should be safe.

Note that we now cast the return value to int at the caller side. There we actually substract it and want to catch the case where the result gets negative. Since all the involved values are quite small compared to INT_MAX I decided to just cast it without further checks.

Change-Id I71e9d4a61d37483685723c16e98f59755694cadf

---
M src/openvpn/ssl.c

1 file changed, 3 insertions(+), 12 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/97/1297/1

src/openvpn/ssl.c +3 -12
index 567560f..dfbbbc6 100644
@@ -180,21 +180,16 @@
     frame->tun_mtu = max_int(frame->tun_mtu, TLS_CHANNEL_MTU_MIN);
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 /**
  * calculate the maximum overhead that control channel frames have
  * This includes header, op code and everything apart from the
  * payload itself. This method is a bit pessimistic and might give higher
  * overhead than we actually have */
-static int
+static size_t
 calc_control_channel_frame_overhead(const struct tls_session *session)
 {
     const struct key_state *ks = &session->key[KS_PRIMARY];
-    int overhead = 0;
+    size_t overhead = 0;
 
     /* opcode */
     overhead += 1;
@@ -227,10 +222,6 @@
     return overhead;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 void
 init_ssl_lib(void)
 {
@@ -2651,7 +2642,7 @@
     int max_pkt_len = min_int(TLS_CHANNEL_BUF_SIZE, session->opt->frame.tun_mtu);
 
     /* Subtract overhead */
-    max_pkt_len -= calc_control_channel_frame_overhead(session);
+    max_pkt_len -= (int)calc_control_channel_frame_overhead(session);
 
     /* calculate total available length for outgoing tls ciphertext */
     int maxlen = max_pkt_len * rel_avail;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1297?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I71e9d4a61d37483685723c16e98f59755694cadf
Gerrit-Change-Number: 1297
Gerrit-PatchSet: 1
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]...>

#2 lore raw
In reply to a message not in the archive

Attention is currently required from: flichtenheld.

plaisthos has posted comments on this change by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1297?usp=email )

Change subject: ssl: change return type of calc_control_channel_frame_overhead to size_t
......................................................................

Patch Set 4: Code-Review+2

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1297?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: comment
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I71e9d4a61d37483685723c16e98f59755694cadf
Gerrit-Change-Number: 1297
Gerrit-PatchSet: 4
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: flichtenheld <[email protected]...>
Gerrit-Comment-Date: Tue, 11 Nov 2025 16:21:01 +0000
Gerrit-HasComments: No
Gerrit-Has-Labels: Yes

#3 lore raw

PATCH v4 1/1 ssl: change return type of calc_control_channel_frame_overhead to size_t

In reply to a message not in the archive

From: Frank Lichtenheld <[email protected]...>

This avoids dealing with conversion warnings inside the function. Since we only add values that are supposed to be positive this should be safe.

Note that we now cast the return value to int at the caller side. There we actually substract it and want to catch the case where the result gets negative. Since all the involved values are quite small compared to INT_MAX I decided to just cast it without further checks.

Change-Id I71e9d4a61d37483685723c16e98f59755694cadf

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1297
---

This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master.

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1297
This mail reflects revision 4 of this Change.

Acked-by according to Gerrit (reflected above):
Arne Schwabe <[email protected]...>

src/openvpn/ssl.c +3 -12
index 908854a..eb5c4fc 100644
@@ -179,21 +179,16 @@
     frame->tun_mtu = max_int(frame->tun_mtu, TLS_CHANNEL_MTU_MIN);
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 /**
  * calculate the maximum overhead that control channel frames have
  * This includes header, op code and everything apart from the
  * payload itself. This method is a bit pessimistic and might give higher
  * overhead than we actually have */
-static int
+static size_t
 calc_control_channel_frame_overhead(const struct tls_session *session)
 {
     const struct key_state *ks = &session->key[KS_PRIMARY];
-    int overhead = 0;
+    size_t overhead = 0;
 
     /* opcode */
     overhead += 1;
@@ -226,10 +221,6 @@
     return overhead;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 void
 init_ssl_lib(void)
 {
@@ -2650,7 +2641,7 @@
     int max_pkt_len = min_int(TLS_CHANNEL_BUF_SIZE, session->opt->frame.tun_mtu);
 
     /* Subtract overhead */
-    max_pkt_len -= calc_control_channel_frame_overhead(session);
+    max_pkt_len -= (int)calc_control_channel_frame_overhead(session);
 
     /* calculate total available length for outgoing tls ciphertext */
     int maxlen = max_pkt_len * rel_avail;
#4 lore raw

[Openvpn-devel] [PATCH applied] Re: ssl: change return type of calc_control_channel_frame_overhead to size_t

Some leeway here in "how to fix the warnings in a good way" - size_t is quite reasonably here. Arne ACKed, BB greened, ship it!

Your patch has been applied to the master branch.

commit 8b0554d988f6bfdefd30620290ec8ff690a37ce2

Author: Frank Lichtenheld
Date:   Tue Nov 11 18:24:31 2025 +0100
     ssl: change return type of calc_control_channel_frame_overhead to size_t

     Signed-off-by: Frank Lichtenheld <[email protected]...>
     Acked-by: Arne Schwabe <[email protected]...>
     Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1297
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg34326.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering

#5 lore raw
In reply to a message not in the archive

cron2 has uploaded a new patch set (#5) to the change originally created by flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1297?usp=email )

The following approvals got outdated and were removed:
Code-Review+2 by plaisthos

Change subject: ssl: change return type of calc_control_channel_frame_overhead to size_t
......................................................................

ssl: change return type of calc_control_channel_frame_overhead to size_t

This avoids dealing with conversion warnings inside the function. Since we only add values that are supposed to be positive this should be safe.

Note that we now cast the return value to int at the caller side. There we actually substract it and want to catch the case where the result gets negative. Since all the involved values are quite small compared to INT_MAX I decided to just cast it without further checks.

Change-Id I71e9d4a61d37483685723c16e98f59755694cadf

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1297
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg34326.html

---
M src/openvpn/ssl.c

1 file changed, 3 insertions(+), 12 deletions(-)

git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/97/1297/5

src/openvpn/ssl.c +3 -12
index e21ac78..d7f55dd 100644
@@ -179,21 +179,16 @@
     frame->tun_mtu = max_int(frame->tun_mtu, TLS_CHANNEL_MTU_MIN);
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 /**
  * calculate the maximum overhead that control channel frames have
  * This includes header, op code and everything apart from the
  * payload itself. This method is a bit pessimistic and might give higher
  * overhead than we actually have */
-static int
+static size_t
 calc_control_channel_frame_overhead(const struct tls_session *session)
 {
     const struct key_state *ks = &session->key[KS_PRIMARY];
-    int overhead = 0;
+    size_t overhead = 0;
 
     /* opcode */
     overhead += 1;
@@ -226,10 +221,6 @@
     return overhead;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 void
 init_ssl_lib(void)
 {
@@ -2650,7 +2641,7 @@
     int max_pkt_len = min_int(TLS_CHANNEL_BUF_SIZE, session->opt->frame.tun_mtu);
 
     /* Subtract overhead */
-    max_pkt_len -= calc_control_channel_frame_overhead(session);
+    max_pkt_len -= (int)calc_control_channel_frame_overhead(session);
 
     /* calculate total available length for outgoing tls ciphertext */
     int maxlen = max_pkt_len * rel_avail;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1297?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I71e9d4a61d37483685723c16e98f59755694cadf
Gerrit-Change-Number: 1297
Gerrit-PatchSet: 5
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>

#6 lore raw
In reply to a message not in the archive

cron2 has submitted this change. ( http://gerrit.openvpn.net/c/openvpn/+/1297?usp=email )

Change subject: ssl: change return type of calc_control_channel_frame_overhead to size_t
......................................................................

ssl: change return type of calc_control_channel_frame_overhead to size_t

This avoids dealing with conversion warnings inside the function. Since we only add values that are supposed to be positive this should be safe.

Note that we now cast the return value to int at the caller side. There we actually substract it and want to catch the case where the result gets negative. Since all the involved values are quite small compared to INT_MAX I decided to just cast it without further checks.

Change-Id I71e9d4a61d37483685723c16e98f59755694cadf

Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1297
Message-Id: <[email protected]...>
URL: https://www.mail-archive.com/[email protected]/msg34326.html

---
M src/openvpn/ssl.c

1 file changed, 3 insertions(+), 12 deletions(-)
src/openvpn/ssl.c +3 -12
index e21ac78..d7f55dd 100644
@@ -179,21 +179,16 @@
     frame->tun_mtu = max_int(frame->tun_mtu, TLS_CHANNEL_MTU_MIN);
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wconversion"
-#endif
-
 /**
  * calculate the maximum overhead that control channel frames have
  * This includes header, op code and everything apart from the
  * payload itself. This method is a bit pessimistic and might give higher
  * overhead than we actually have */
-static int
+static size_t
 calc_control_channel_frame_overhead(const struct tls_session *session)
 {
     const struct key_state *ks = &session->key[KS_PRIMARY];
-    int overhead = 0;
+    size_t overhead = 0;
 
     /* opcode */
     overhead += 1;
@@ -226,10 +221,6 @@
     return overhead;
 }
 
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif
-
 void
 init_ssl_lib(void)
 {
@@ -2650,7 +2641,7 @@
     int max_pkt_len = min_int(TLS_CHANNEL_BUF_SIZE, session->opt->frame.tun_mtu);
 
     /* Subtract overhead */
-    max_pkt_len -= calc_control_channel_frame_overhead(session);
+    max_pkt_len -= (int)calc_control_channel_frame_overhead(session);
 
     /* calculate total available length for outgoing tls ciphertext */
     int maxlen = max_pkt_len * rel_avail;

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1297?usp=email
To unsubscribe, or for help writing mail filters, visit http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: merged
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: I71e9d4a61d37483685723c16e98f59755694cadf
Gerrit-Change-Number: 1297
Gerrit-PatchSet: 5
Gerrit-Owner: flichtenheld <[email protected]...>
Gerrit-Reviewer: plaisthos <[email protected]...>
Gerrit-CC: openvpn-devel <[email protected]>